package ddd2;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.Scanner;

public class GuessNum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random rand = new Random();
        LocalDateTime Start = LocalDateTime.now();
        int theNumber = rand.nextInt(100)+1;
        int chooseNumber = 7;
        while(chooseNumber != 0){
            System.out.println("Choose number between 1 and 100");
            System.out.println("你还有" + chooseNumber + "次机会");
            chooseNumber -= 1;
            int num = sc.nextInt();
            if(num > theNumber){
                System.out.println("偏大");
            }
            else if (num<theNumber) {
                System.out.println("偏小");
            }
            if(num == theNumber){
                System.out.println("Yes");
                Duration duration = Duration.between(Start, LocalDateTime.now());
                System.out.println("你花了" + duration.getSeconds() + " seconds");
                break;
            }else if(theNumber - num <5 && theNumber - num > -5){
                System.out.println("相差很近了嗷");
            }else{
                System.out.println("No");
                if(chooseNumber == 0){
                    System.out.println("你失败了");
                }
            }
        }

    }
}
